package com.sskj.award.ui.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Keep;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.award.R;
import com.sskj.award.R2;
import com.sskj.award.bean.AirDropBean;
import com.sskj.award.bean.KongTouBean;
import com.sskj.award.presenter.CommunityPerformanceFragmentPresenter;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.common.util.ClickUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.adapter.BaseAdapter;
import com.sskj.lib.adapter.ViewHolder;
import com.sskj.lib.base.BaseFragment;
import com.sskj.lib.util.NumberUtil;
import com.sskj.lib.util.TimeFormatUtil;
import com.sskj.lib.widget.BottomDialog;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @ClassName: DetailsAssetsFragment
 * @Description: java类作用描述:社区业绩fragment
 * @Author: yuanlin
 * @Date: 2019/7/12 15:45
 */
@Route(path = RConfig.SUPER_SUPER_COMMUNITY_PERFORMANCE)
public class CommunityPerformanceFragment extends BaseFragment<CommunityPerformanceFragmentPresenter> {

    @BindView(R2.id.tvShowNumberOfDirectAirDrops)
    TextView tvShowNumberOfDirectAirDrops;
    @BindView(R2.id.tvShowNumberOfCommunityAirDrops)
    TextView tvShowNumberOfCommunityAirDrops;
    @BindView(R2.id.tvShowAccumulatedDirectPushAward)
    TextView tvShowAccumulatedDirectPushAward;
    @BindView(R2.id.tvShowAccumulatedCommunityAwards)
    TextView tvShowAccumulatedCommunityAwards;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.llSop)
    LinearLayout llSop;
    @BindView(R2.id.tvSOP)
    TextView tvSOP;
    private AirDropBean data;
    private String state = "SOP";
    private BaseAdapter<KongTouBean.DataBean> adapter;
    private int page = 1;

    @Override
    protected int getLayoutId() {
        return R.layout.super_layout_fragment_community_performance;
    }

    @Override
    protected CommunityPerformanceFragmentPresenter getPresenter() {
        return new CommunityPerformanceFragmentPresenter();
    }

    @Override
    protected void initView() {
        super.initView();
        mPresenter.getAirData();
        mPresenter.getAirStateData("SOP", String.valueOf(page), true);
        ClickUtil.click(300, llSop, () -> {
            BottomDialog.changeLanguge(getActivity(), new BottomDialog.OnSure() {
                @Override
                public void onSure(String tv) {
                    state = tv;
                    setCommunityData();
                    tvSOP.setText(tv);
                }
            });
        });

        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(getContext())
                .setLeftPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 30))
                .setRightPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 30))
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 1))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.super_divi_split))
        );


    }

    @SuppressLint("SetTextI18n")
    private void setCommunityData() {
        if (data == null) {
            return;
        }
        if (state.equals("SOP")) {
            AirDropBean.SOPBean sop = data.getSOP();
            if (sop == null) {
                return;
            }
            tvShowNumberOfDirectAirDrops.setText(NumberUtil.keepNoZero(NumberUtil.keep(sop.getZhitui_kongtou_total(), 6)) + sop.getCode());
            tvShowNumberOfCommunityAirDrops.setText(NumberUtil.keepNoZero(NumberUtil.keep(sop.getCommunity_kongtou_total(), 6)) + sop.getCode());
            tvShowAccumulatedDirectPushAward.setText(NumberUtil.keepNoZero(NumberUtil.keep(sop.getZhitui_award_total(), 6)) + sop.getCode());
            tvShowAccumulatedCommunityAwards.setText(NumberUtil.keepNoZero(NumberUtil.keep(sop.getCommunity_award_total(), 6)) + sop.getCode());
            mPresenter.getAirStateData("SOP", String.valueOf(page), true);
        }

        if (state.equals("CNB")) {
            AirDropBean.CNBBean cnb = data.getCNB();
            if (cnb == null) {
                return;
            }
            mPresenter.getAirStateData("CNB", String.valueOf(page), true);
            tvShowNumberOfDirectAirDrops.setText(NumberUtil.keepNoZero(NumberUtil.keep(cnb.getZhitui_kongtou_total(), 6)) + cnb.getCode());
            tvShowNumberOfCommunityAirDrops.setText(NumberUtil.keepNoZero(NumberUtil.keep(cnb.getCommunity_kongtou_total(), 6)) + cnb.getCode());
            tvShowAccumulatedDirectPushAward.setText(NumberUtil.keepNoZero(NumberUtil.keep(cnb.getZhitui_award_total(), 6)) + cnb.getCode());
            tvShowAccumulatedCommunityAwards.setText(NumberUtil.keepNoZero(NumberUtil.keep(cnb.getCommunity_award_total(), 6)) + cnb.getCode());
        }

        if (state.equals("LAC")) {
            AirDropBean.LACBean lac = data.getLAC();
            if (lac == null) {
                return;
            }
            mPresenter.getAirStateData("LAC", String.valueOf(page), true);
            tvShowNumberOfDirectAirDrops.setText(NumberUtil.keepNoZero(NumberUtil.keep(lac.getZhitui_kongtou_total(), 6)) + lac.getCode());
            tvShowNumberOfCommunityAirDrops.setText(NumberUtil.keepNoZero(NumberUtil.keep(lac.getCommunity_kongtou_total(), 6)) + lac.getCode());
            tvShowAccumulatedDirectPushAward.setText(NumberUtil.keepNoZero(NumberUtil.keep(lac.getZhitui_award_total(), 6)) + lac.getCode());
            tvShowAccumulatedCommunityAwards.setText(NumberUtil.keepNoZero(NumberUtil.keep(lac.getCommunity_award_total(), 6)) + lac.getCode());
        }
    }

    @SuppressLint("SetTextI18n")
    public void getAirDataSuccess(AirDropBean data) {
        if (data == null) {
            return;
        }
        this.data = data;
        AirDropBean.SOPBean sop = data.getSOP();
        if (sop == null) {
            return;
        }
        tvShowNumberOfDirectAirDrops.setText(NumberUtil.keepNoZero(NumberUtil.keep(sop.getZhitui_kongtou_total(), 6)) + sop.getCode());
        tvShowNumberOfCommunityAirDrops.setText(NumberUtil.keepNoZero(NumberUtil.keep(sop.getCommunity_kongtou_total(), 6)) + sop.getCode());
        tvShowAccumulatedDirectPushAward.setText(NumberUtil.keepNoZero(NumberUtil.keep(sop.getZhitui_award_total(), 6)) + sop.getCode());
        tvShowAccumulatedCommunityAwards.setText(NumberUtil.keepNoZero(NumberUtil.keep(sop.getCommunity_award_total(), 6)) + sop.getCode());
    }

    public void getAirStateDataSuccess(KongTouBean data) {
        if (data == null) {
            return;
        }
        adapter = new BaseAdapter<KongTouBean.DataBean>(R.layout.super_platform_item_record, null, recyclerView,true) {
            @Override
            public void bind(ViewHolder holder, KongTouBean.DataBean item) {
                holder.setText(R.id.tvDescribe1, NumberUtil.keepNoZero(NumberUtil.keep(item.getMoney(), 6)) + "USDT")
                        .setText(R.id.tvDescribe3, item.getCreated_at());
                switch (item.getType()) {
                    case 1:
                        holder.setText(R.id.tvDescribe2, App.INSTANCE.getString(R.string.super_superPlatformActivity3));
                        break;
                    case 2:
                        holder.setText(R.id.tvDescribe2, App.INSTANCE.getString(R.string.super_superPlatformActivity4));
                        break;
                    case 3:
                        holder.setText(R.id.tvDescribe2, App.INSTANCE.getString(R.string.super_superPlatformActivity5));
                        break;
                }
            }
        };
        adapter.addData(data.getData());
    }
}
